/**
 * @公司:公约树
 * @位置:苏州
 * @Classname Anime03imageArray
 * @Date 2022-06-12 下午 12:34
 * @Created by hanWanLu
 * @auther 中文:韩万路
 */


package com.animeJavaExample;

import com.animeJava.core.AnimeJava;
import com.animeJava.dao.animeEvent.AnimeImagRender;
import com.animeJava.mode.animeModel.AnimeImageProperty;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.embed.swing.SwingFXUtils;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.*;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

import java.awt.image.BufferedImage;

/**
 * 播放图片序列
 */
public class Anime03imageArray extends Application {
    public static void main(String[] args) {
        launch(args);
    }


    @Override
    public void start(Stage stage) throws Exception {
        AnchorPane vBox = new AnchorPane();
        Scene scene = new Scene(vBox);
        stage.setScene(scene);
        stage.setHeight(300);
        stage.setWidth(300);
        stage.setTitle("播放序列图片");
        stage.initStyle(StageStyle.TRANSPARENT);
        scene.setFill(null);
        stage.setAlwaysOnTop(true);
        vBox.setStyle("-fx-background-color: #00000000");

        Button imageView = new Button();
        vBox.getChildren().add(imageView);
        imageView.setPrefHeight(200);
        imageView.setPrefWidth(200);
        imageView.setDisable(true);
        imageView.setOpacity(1);

        AnimeImageProperty animeImageProperty = new AnimeImageProperty();
        animeImageProperty.setImageFPS(24);
        animeImageProperty.setImageArrayPath(this.getClass().getResource("/imageArray").toURI());
        animeImageProperty.setLoop(true);
        animeImageProperty.setUpdate(new AnimeImagRender() {
            @Override
            public void run(Double timeTo, BufferedImage imageArrayBuffer) {
                Platform.runLater(new Runnable() {
                    @Override
                    public void run() {
                        Image mainiamge = SwingFXUtils.toFXImage( imageArrayBuffer, null);
                        BackgroundImage backgroundImage = new BackgroundImage(mainiamge , null ,null, null , new BackgroundSize(200,200  , true ,true , true ,true));
                        Background background = new Background(backgroundImage);
                        imageView.setBackground(background);
                    }
                });
            }
        });

        AnimeJava animeJava = new AnimeJava(animeImageProperty);
        animeJava.play();
        stage.show();
    }
}
